home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 18 / AMIGAplus Sonderheft 18 (1999)(ICP)(DE)[!].iso / Patch / FuerMyst / SetPatch43_6b.lha / SetPatch43_6b / CheckSetPatch.c next >
C/C++ Source or Header  |  1997-12-13  |  4KB  |  114 lines

  1. /*------------------------------------------------------------------------*/
  2. /****** misc/CheckSetPatchVersion ****************************************
  3. *
  4. *   NAME
  5. *     CheckSetPatchVersion - Determine the system SetPatch level
  6. *
  7. *   SYNOPSIS
  8. *       ok = CheckSetPatchVersion(SysBase, version, revision);
  9. *
  10. *       BOOL CheckSetPatchVersion(struct ExecBase *, UWORD, UWORD);
  11. *
  12. *   FUNCTION
  13. *       Determines and checks if at least a required SetPatch is
  14. *       installed. This is for software that wants to exploit
  15. *       knowledge about installed bug fixes to avoid internal hacks
  16. *       around OS bugs.
  17. *
  18. *   INPUTS
  19. *     SysBase   - A pointer to ExecBase.
  20. *
  21. *     version   - The minimum acceptable version of SetPatch
  22. *
  23. *     revision  - The minimum acceptable revision of SetPatch
  24. *
  25. *   RESULT
  26. *     ok        - This tells you if at least the patch you are looking
  27. *                 for is installed.
  28. *
  29. *   EXAMPLE
  30. *
  31. *   NOTES
  32. *       The result is valid until the system is rebooted. This function
  33. *       will continue to work in a future OS if you heed the warnings.
  34. *
  35. *       Once a bug has been fixed in SetPatch, you can rest assured that
  36. *       either a future OS or a future SetPatch will also contain that
  37. *       bug fix. It is unlikely that fixed things are intentionally broken
  38. *       again.
  39. *
  40. *       Obviously it is not enough to check the SetPatch version to see
  41. *       if a bug is fixed. First you must make sure that you are using the
  42. *       OS version that exhibits the bug to be fixed by SetPatch. Afterall
  43. *       a SetPatch V43 can't e.g. fix V39 bugs on a V37 based Amiga.
  44. *
  45. *       DO NOT USE THIS FUNCTION TO SEE IF A BUG IS PRESENT! There is no
  46. *       guarantee at all that any bug fix is not installed if this function
  47. *       returns FALSE. Don't rely on side effects of any bug! This function
  48. *       has been designed to tell you if known problems are fixed, not for
  49. *       the contrary or any other interpretation of this description.
  50. *
  51. *       An 68K C compiler will generate less than 80 bytes for this also
  52. *       ROMable function. There is little to be gained by recoding this in
  53. *       assembler. You only lose portability completely.
  54. *
  55. *   SEE ALSO
  56. *
  57. *   BUGS
  58. *       Prior to the release in December 1997, the actual version check
  59. *       in this function was buggy. It basically didn't work as expected.
  60. *       It should work now.
  61. *
  62. ******************************************************************************
  63. *
  64. */
  65. /*------------------------------------------------------------------------*/
  66. /* Only ps_Version and ps_Revision may be accessed! Read only!
  67.  * Do not try anything. This is off limits!
  68.  */
  69. struct SetPatchSemaphore
  70. {
  71.     struct SignalSemaphore  sps_Sem;        /* Don't touch! */
  72.     struct MinList          sps_Private;    /* Don't touch! */
  73.     UWORD                   sps_Version;    /* Version installed */
  74.     UWORD                   sps_Revision;   /* Revision installed */
  75.     /* Don't touch! */
  76. };
  77.  
  78. /*------------------------------------------------------------------------*/
  79. BOOL CheckSetPatchVersion(struct ExecBase *SysBase,
  80.                           UWORD version, UWORD revision)
  81. {
  82.     struct SetPatchSemaphore *sem;
  83.     BOOL foundsetpatch = FALSE;
  84.  
  85.     /* This may look strange, but it is ok.
  86.      * An installed SetPatch will never be removed and once it
  87.      * has been installed its version/revision won't change.
  88.      * This is _guaranteed_!
  89.      * So if the semaphore exists, it will never disappear again.
  90.      * The result is that we can keep the Forbid (Yuck!) very short.
  91.      * We pass in SysBase to be able to avoid any global/$4 access.
  92.      */
  93.     Forbid();
  94.     sem = (struct SetPatchSemaphore *)FindSemaphore((STRPTR)"« SetPatch »");
  95.     Permit();
  96.  
  97.     if(sem)
  98.     {
  99.         /* Do we have at least the requested version/revision? */
  100.         /* NOTE: Previously this test was strangely inverted! */
  101.         if((sem->sps_Version > version) ||
  102.            ((version == sem->sps_Version) && (sem->sps_Revision >= revision)))
  103.         {
  104.             /* Yes, we got it. The requested SetPatch has been installed */
  105.             foundsetpatch = TRUE;
  106.         } /* if */
  107.     } /* if */
  108.  
  109.     return(foundsetpatch);
  110.  
  111. } /* CheckSetPatchVersion */
  112.  
  113.  
  114.